/*
 * @Author: Wangjun
 * @Date: 2023-08-14 10:40:47
 * @LastEditTime: 2023-09-03 21:38:30
 * @LastEditors: Wangjun
 * @Description:
 * @FilePath: \nodex\nodecmp\op_between.go
 * hnxr
 */
package nodecmp

import (
	"gitee.com/hnxr_1/nodex"
)

//0:> 1>= 2 < 3:<= 4== 5 !=
//M

func init() {
	nodex.Reister(new(Between))
}

type Between struct {
	nodex.Node
	X   nodex.Double  `remark:"最小值"`
	Min nodex.Double  `remark:"最小值"`
	Max nodex.Double  `remark:"最大值"`
	Y   nodex.Boolean `remark:"输出Y,,out"`
}

func (m *Between) GetModelID() int {
	return nodex.ModCmp
}

func (m *Between) GetName() string {
	return "BETWEEN"
}

/**
 * @description: 节点信息
 * @return {*}
 */
func (m *Between) RegData() []byte {
	return nodex.MakeRegData(m, "X在最小最大值之间", m.GetName(), "")
}

// //0:> 1>= 2 < 3:<= 4== 5 !=
func (m *Between) Calc() (err error) {
	if m.EnQ {
		if *m.Min.Bad || *m.Max.Bad || *m.X.Bad {
			m.Bad = true
			m.Y.Value = false
			return //不计算
		}
	}

	m.Bad = false
	if m.X.Value >= m.Min.Value && m.X.Value <= m.Max.Value {
		m.Y.Value = true
		return
	}
	m.Y.Value = false
	return
}
